<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>STAF Service Development in Java using Eclipse</title>
</head>
<body>
<h1>STAF Service Development in Java using Eclipse</h1>
To create a .jar file from a project named MyStaf from a class named
MyService that will correctly load as a STAF service:
<br>
<br>
<ul>
	<li>First, add an entry in STAF.cfg that looks like this example:<br>
	<code>SERVICE MyService library JSTAF execute
	/Library/staf/lib/MyService.jar</code><br>
	<br>

	STAF doesn't care where you put the jars to use or what you call the
	service. The service name and the name for the .jar file don't have to
	be related.</li>
	<br>
	
	<li>Then set the build output folder to something like <code>MyProject/STAF-INF/classes</code>:
	<ol>
		<li>from the Eclipse <strong>Project</strong>menu, select <strong>Properties...</strong></li>
		<li>click on the <strong>Source</strong> tab/button.</li>
		<li>at the bottom, enter the <strong>default source
		output folder.</strong> Example: <br>
		<br>
		<code> /MyProject/build/STAF-INF/classes</code></li>
		<br>
		<li>While the folder names above STAF-INF don't matter, you must
		create and use STAF-INF/classes folder structure, because this is what
		STAFProc is expecting. When the .class file is built, it will be put
		into a directory structure according to your package declaration.
		Example:<br>
		<br>
		<pre><code>/MyProject/build/STAF-INF/classes/com/ibm/staf/service/MyProject/MyService.class</code></pre></li>
	</ol>
			<li>Install the following .jar files into STAF-INF, which should have come with the jaxws distribution:
				<ul>
					<li>jaxb-api.jar</li>
					<li>jaxws-api.jar</li>
					<li>jaxws-rt.jar</li>
					<li>jsr173_api.jar</li>
					<li>jsr181-api.jar</li>
				</ul>
			</li>
	<br>
	<li>Build the Java archive file, or .jar file:
	<ol>
		<li>Navigate to and right-click on MyService.class and click <b>Export...</b>
		</li>
		<li>Use the following settings:</li>
		<ul>
			<li>expand <b>Java</b>, click <b>JAR file</b> and click <b>Next</b>.
			</li>
			<li>check <b>Export generated class files and resources</b></li>
			<li>Under "<b>Options</b>," check <b>Add directory entries</b>
			(otherwise STAF will complain about being unable to find the class)</li>
			<li>click <b>Next</b></li>
			<li>check <b>Build projects</b> if not built automatically
			(default)</li>
			<li>click <b>Next</b></li>
			<li>click <b>Use existing manifest from workspace</b></li>
			<li>click <b>Finish</b></li>
		</ul>
		<li>Browse to the MANIFEST.MF file you created per the directions
		from the STAF Service documentation. It doesn't matter where this
		manifest file is located, but it must be called MANIFEST.MF. Inside
		MANIFEST.MF, you should enter text like this example: <pre><code>
      	Manifest-Version: 1.0

      	Name: staf/service/info
      	Service-Class: com.ibm.staf.service.MyProject.MyService
</code></pre></li>
		[Edit:]BE SURE to have the blank line there (see some following posts
		for the various error messages you can get). Note also that it has the
		MuWSDL class name added, as compared to the directions for this on the
		STAF Service Deveoper's Guide page. The STAF Developer's Guide is
		incorrect; it should read instead:
		<br>

		<blockquote>Service-Class:
		com.ibm.staf.service.deviceservice.DeviceService</blockquote>

		If you follow the (incorrect) instructions, STAFProc will emit an
		error on startup, saying it cannot find the class. This was a
		significant source of confusion for me until I realized the problem.
	</li>
	<li>click <strong>Finish.</strong></li>
	</ol>
	<li>Copy the resulting MyService.jar over to the location you've
	specified in STAF.cfg.</li>
	<br>
	<li>You can make sure that the .jar file has the right entries by
	typing <code>jar tf MyService.jar</code>. The output should list the
	class file, the Manifest (under META-INF), and all the subdirectories
	above the class file (in STAF-INF). Example: <pre><code>
$ jar tf /Volumes/mountedimage/MyProject/MyService.jar 
      META-INF/MANIFEST.MF
      STAF-INF/
      STAF-INF/classes/
      STAF-INF/classes/com/
      STAF-INF/classes/com/ibm/
      STAF-INF/classes/com/ibm/staf/
      STAF-INF/classes/com/ibm/staf/service/
      STAF-INF/classes/com/ibm/staf/service/MyProject/
      STAF-INF/classes/com/ibm/staf/service/MyProject/MyService.class
</code></pre>
</ul>
Your new STAF service should now correctly load, assuming your Java code
is correct and you have all the required STAF methods and whatnot. See
the
<a
	href="http://staf.sourceforge.net/current/stafsdg.html#Header_Debugging_Java_Service">STAF
Service Developer's Guide</a>
section on developing a STAF Service in Java for information on how to
compile the source to a JAR file.

</body>
</html>
